package com.itheima.myscoket;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.InterfaceAddress;
import java.net.MulticastSocket;
import java.nio.channels.MulticastChannel;

public class Demo3 {
    public static void main(String[] args) throws IOException {
        MulticastSocket ms = new MulticastSocket(10000);
        DatagramPacket dp = new DatagramPacket(new byte[1024],1024);
        //把当前计算机绑定一个组播地址
        ms.joinGroup(InetAddress.getByName("224.0.1.1"));
        ms.receive(dp);
        byte[] data = dp.getData();
        int length = dp.getLength();
        System.out.println(new String(data,0,length));
        ms.close();
    }
}
